Skip to content

types: make Client.on() compatible with esnext.disposable in TS5.6+ #10773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2025

Conversation

Renegade334
Copy link
Contributor

Please describe the changes this PR makes and why it should be merged:

Resolves #10577.

A sticking plaster for v14 to cover this issue, which causes compiler errors when using TS 5.6 or higher under specific conditions. The underlying problem is that the EventEmitter.on() iterator now extends AsyncIteratorObject in TS 5.6+, which becomes an AsyncDisposable if lib.esnext.disposable is loaded, whereas the override signature in the v14 types uses the older AsyncIterableIterator, which isn't AsyncDisposable and so causes an assignability mismatch.

AsyncIteratorObject doesn't exist in TypeScript 5.5 and earlier, so this change provides a custom AsyncIterableIterator interface that matches whether the return type of the parent EventEmitter.on() is AsyncDisposable or not.

This isn't future-proof against any further changes to the TS iterator types, but this only really needs to hold until v15 ships, and this seems like the least invasive fix.

It's not possible to test this fix within the tsd tests, as the package dependencies use neither an affected version of TypeScript nor an affected version of @types/node; however, manual tests confirm it to be working as intended.

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

@Renegade334 Renegade334 requested a review from a team as a code owner February 21, 2025 20:33
@Renegade334 Renegade334 requested review from vladfrangu, iCrawl, kyranet and SpaceEEC and removed request for a team February 21, 2025 20:33
Copy link

vercel bot commented Feb 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
discord-js ⬜️ Ignored (Inspect) Visit Preview Feb 21, 2025 8:33pm
discord-js-guide ⬜️ Ignored (Inspect) Visit Preview Feb 21, 2025 8:33pm

@didinele didinele merged commit 45552fa into discordjs:v14 Feb 24, 2025
7 checks passed
@Renegade334 Renegade334 deleted the client-static-iterator branch February 24, 2025 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

After upgrading @types/node to v22.7.9, an incompatible type error occurs in the “on” method of the client class
5 participants